/**
 *与后台交互需要修改的有：$(document).ready的window.delLink
 */
$(document).ready(function () {
    initClickable();


});


//封装所有的div显示和隐藏函数
function initClickable(){
    var addSelector = "#add-img-name, #add-txtimg-name";
    var editelector = "#edit-img-name, #edit-txtimg-name";
    //新增幻灯片
    $("#addSlide").click(function(){
        showAddSlide();
    });

    //新增幻灯片的返回按钮
    $("#add-return, #edit-return").click(function(){
        showAllSlides();
    });

    //幻灯片的编辑按钮
    $(".slides-selected .update").each(function(index){
        $(this).click(function(){
            showEditSlide();
        });
    });

    $("#add-ok, #edit-ok").click(function(){
        var currentSelector;
        var currentId = $(this).attr("id");
        var flag = true;
        if(currentId == "add-ok"){
            currentSelector = addSelector;
        }else{
            currentSelector = editelector;
        }
        $(currentSelector).each(function(){
            var value = $(this).val();
            if( value == undefined|| value == null||value==""){
                flag = false;
            }
        });
        if(!flag){
            event.preventDefault();
            alert("请出入完整的信息");
        }
    });
}

//显示所有幻灯片
function showAllSlides(){
    $(".slides-selected").show();
    $(".edit-slide").hide();
    $(".add-slide").hide();
}
//显示添加幻灯片
function showAddSlide(){
    $(".slides-selected").hide();
    $(".edit-slide").hide();
    $(".add-slide").show();
}
//显示编辑幻灯片
function showEditSlide(){
    $(".slides-selected").hide();
    $(".edit-slide").show();
    $(".add-slide").hide();
}


